package com.hzhr.iot.device.sdk.service;

import com.hzhr.iot.core.constant.Common_ErrorsEnum;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrHttpUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import com.hzhr.iot.device.sdk.constant.Device_ErrorsEnum;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDeviceDeleteModel;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDeviceGetModel;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDeviceModel;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDevicePostModel;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDevicePutModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;

@Service
public class Device_CollectDeviceService {
    @Autowired
    RestTemplate restTemplate;

    /**
     * 查询用户管辖范围下的采集设备 <br/><br/>
     * 简介 : 查询用户管辖范围下的采集设备 <br/>
     * 步骤 : <br/>
     * 1. 查询用户管辖范围下的采集设备 <br/>
     * 2. 返回信息 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否设备型号信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_iotDevice : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否所属物联网设备信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_gasUser : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否所属燃气用户信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_gasConsume : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总用气量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_alarmCount : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总报警数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_dept : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示部门信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_outId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示外部系统唯一键;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _is_paging : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否分页;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.ID = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.CODE = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_companyId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.COMPANY_ID = #{_equal_companyId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_deptId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.DEPT_ID = #{_equal_deptId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_deptCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.DEPT_CODE = #{_equal_deptCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_categoryCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.CATEGORY_CODE = #{_equal_categoryCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.CODE like #{_like_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_iotDeviceId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.IOT_DEVICE_ID = #{_equal_iotDeviceId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _like_iotDeviceCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.IOT_DEVICE(关联键：IOT_DEVICE_ID).CODE like #{_like_iotDeviceCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserName : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.GAS_USER_NAME like #{_like_gasUserName};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.GAS_USER_CODE like #{_like_gasUserCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserAddress : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.GAS_USER_ADDRESS like #{_like_gasUserAddress};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _greaterthanorequal_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.CREATE_TIME >= #{_greaterthanorequal_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _lessthan_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.CREATE_TIME < #{_lessthan_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _equal_gasUserId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.GAS_USER_ID = #{_equal_gasUserId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _equal_prodFactoryId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.COLLECT_DEVICE_TYPE(关联键：TYPE_ID).PROD_FACTORY_ID = #{_equal_prodFactoryId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_iotDeviceCompanyName : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.IOT_DEVICE(关联键：IOT_DEVICE_ID).USER_COMPANY(关联键：COMPANY_ID).NAME = #{equal_iotDeviceCompanyName};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_gasUserCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.GAS_USER_CODE = #{_equal_gasUserCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_deptCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.DEPT_CODE like #{_like_deptCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_iotDeviceCompanyId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.IOT_DEVICE(关联键：IOT_DEVICE_ID).COMPANY_ID = #{_equal_iotDeviceCompanyId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_prodFactoryIotCompanyId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where COLLECT_DEVICE.COLLECT_DEVICE_TYPE(关联键：TYPE_ID).PROD_FOCTORY(关联键：PROD_FOCTORY_ID).IOT_COMPANY_ID = #{_equal_prodFactoryIotCompanyId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @throws ServiceException <br/>
     * @see CollectDeviceGetModel result <br/>
     */ 
    public CollectDeviceGetModel get(Map<String, String> header, Map<String, Object> query) throws ServiceException {
        HttpHeaders headers = new HttpHeaders();
        if (header == null) header = new HashMap<>();
        for (Map.Entry<String, String> entry:
        header.entrySet()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        headers.add("Content-Type", "application/json;charset-utf-8");
        headers.add("accept", "application/json");
        HttpEntity httpEntity = new HttpEntity<>(null, headers);

        Map<String, Object> uriVariables = new HashMap<>();

        try {
            ResponseEntity<CollectDeviceGetModel> result = restTemplate.exchange("http://device-service/collect-devices?" + HzhrHttpUtil.queryMap2url(query), HttpMethod.GET, httpEntity, CollectDeviceGetModel.class, uriVariables);
            return result.getBody();
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            if (e.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_2"));
            }
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
            } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("COLLECTDEVICESERVICE_GET_" + code));
            }
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
             } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("COLLECTDEVICESERVICE_GET_" + code));
             }
        } catch (Throwable e) {
              e.printStackTrace();
              throw e;
        }
    }
    /**
     * 查询采集设备 <br/><br/>
     * 简介 : 查询采集设备 <br/>
     * 步骤 : <br/>
     * 1. 查询采集设备 : (√) <br/>
     * 根据条件参数查询采集设备(COLLECT_DEVICE)对象collectDevice_1； <br/>
     * collectDevice_1.gasConsume属性说明： <br/>
     *           对应于collectDevice_1所关联的第一个采集数据(COLLECT_DATA)对象(关联方式：COLLECT_DEVICE.ID = COLLECT_DATA.COLLECT_DEVICE_ID)的currentValue属性； <br/>
     * collectDevice_1.gasConsume属性说明： <br/>
     *           对应于collectDevice_1所关联的报警数据(ALARM_DATA)对象(关联方式：COLLECT_DEVICE.ID = COLLECT_DATA.COLLECT_DEVICE_ID)集合的数量； <br/>
     * 2. 返回信息 : (√) <br/>
     * 根据条件参数和查询到结果组装结果对象并返回， <br/>
     * CollectDeviceGetModel中CollectDeviceModel的managementName属性说明： <br/>
     *           对应于CollectDeviceModel模型所关联的user_service.DeptModel模型(关联方式：CollectDeviceModel.deptId = user_service.DeptModel)的managementName属性； <br/>
     * CollectDeviceGetModel模型中CollectDeviceModel模型的subCompanyName属性说明： <br/>
     *           对应于CollectDeviceModel模型所关联的user_service.DeptModel模型(关联方式：CollectDeviceModel.deptId = user_service.DeptModel)的subCompanyName属性； <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_info : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示详情;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示设备型号信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_iotDevice : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示所属物联网设备信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_gasUser : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示所属燃气用户信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_gasConsume : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总用气量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_alarmCount : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总报警数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _show_dept : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示部门信息;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _is_paging : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否分页;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/>
     * _page : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 页数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _count : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 每页数量;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 1;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.id = #{_equal_id};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.code = #{_equal_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_companyId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.companyId = #{_equal_companyId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_deptId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.deptId = #{_equal_deptId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_deptCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.deptCode = #{_equal_deptCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _equal_categoryCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.categoryCode = #{_equal_categoryCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.code like #{_like_code};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_iotDeviceId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.iotDeviceId = #{_equal_iotDeviceId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _like_iotDeviceCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.iotDeviceCode like #{_like_iotDeviceCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserName : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.gasUserName like #{_like_gasUserName};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.gasUserCode like #{_like_gasUserCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserAddress : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.gasUserAddress like #{_like_gasUserAddress};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _greaterthanorequal_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.createTime >= #{_greaterthanorequal_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _lessthan_createTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.createTime < #{_lessthan_createTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _equal_gasUserId : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.gasUserId = #{_equal_gasUserId};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : long;<br/>
     * _equal_gasUserCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件 : where CollectDeviceModel.gasUserCode = #{_equal_gasUserCode};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/><br/>
     * @throws ServiceException <br/>
     * @see CollectDeviceGetModel result <br/>
     */ 
    public CollectDeviceGetModel get2(Map<String, String> header, Map<String, Object> query) throws ServiceException {
        HttpHeaders headers = new HttpHeaders();
        if (header == null) header = new HashMap<>();
        for (Map.Entry<String, String> entry:
        header.entrySet()) {
            headers.add(entry.getKey(), entry.getValue());
        }
        headers.add("Content-Type", "application/json;charset-utf-8");
        headers.add("accept", "application/json");
        HttpEntity httpEntity = new HttpEntity<>(null, headers);

        Map<String, Object> uriVariables = new HashMap<>();

        try {
            ResponseEntity<CollectDeviceGetModel> result = restTemplate.exchange("http://device-service/v2/collect-devices?" + HzhrHttpUtil.queryMap2url(query), HttpMethod.GET, httpEntity, CollectDeviceGetModel.class, uriVariables);
            return result.getBody();
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            if (e.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_2"));
            }
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
            } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("COLLECTDEVICESERVICE_GET2_" + code));
            }
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            ResponseExceptionDto response = HzhrJsonUtil.json2object(e.getResponseBodyAsString(), ResponseExceptionDto.class);
            Integer code = response.getCode();
            if (code <= 100) {
                throw new ServiceException(Common_ErrorsEnum.getEnumByName("COMMON_" + code));
             } else {
                 throw new ServiceException(Device_ErrorsEnum.getEnumByName("COLLECTDEVICESERVICE_GET2_" + code));
             }
        } catch (Throwable e) {
              e.printStackTrace();
              throw e;
        }
    }
}

